using Kopernikus.Parsing.GenericActions;
using Kopernikus.Parsing.GenericParsing;
using NUnit.Framework;

namespace Kopernikus.Parsing.Tests.GenericParsing
{
    [TestFixture]
    public class TestFailOnBadHandlers
    {
        private class P_BadParam
        {
            [CfgStart("P -> X")]
            public string t_default(int s)
            {
                return "";
            }
        }

        private class P_BadParamCount
        {
            [CfgStart("P -> X")]
            public string p(string s1, string s2)
            {
                return "";
            }
        }

        private class P_BadReturnValue
        {
            [CfgStart("P -> X")]
            public int p(string s)
            {
                return 0;
            }
        }

        private static void TestParser<TParser>() where TParser : new()
        {
            try
            {
                GenericParser<TParser, string> lexer = GenericParser<TParser, string>.Create(new TParser());
                Assert.Fail();
            }
            catch (InvalidGenericActionException)
            {
            }
        }

        public void Test()
        {
            TestParser<P_BadParam>();
            TestParser<P_BadParamCount>();
            TestParser<P_BadReturnValue>();
        }
    }
}